package thread.synchronized_;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2024-03-07
 * Time:19:08
 */
public class NonStaticMethod {
    public static void main(String[] args) {
        M2 m2 = new M2();
        for (int i = 0; i < 5; i++) {
            new Thread(m2).start();
        }
    }
}
class M2 implements Runnable{
    @Override
    public void run() {
        func();
    }
    public synchronized void func() {//非静态方法,锁定的是调用对象,即M2的实例化对象
        System.out.println("start...");
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println("end...");
    }
}